<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
	</head>
	<body>
		<div class="right-sidebar" style="max-width: 1200px;position: relative">
			<ul class="nav nav-tabs">
				<li role="presentation" class="active"><a href="playerManage.html">ID查询</a></li>
				<li role="presentation"><a href="nicknameSearch.html">昵称查询</a></li>
			</ul>

			<div class="input-group col-md-12" style="margin: 10px auto;">
			  <input type="number" min="0" class="form-control" placeholder="请输入游戏ID" name="user_id" id="user_id">
			  <span class="input-group-addon" id="cbtn">查询</span>
			</div>
			<section class="table-responsive">
				<table class="table table-bordered" style="border: 1px solid #ddd;">
					<thead>
						<tr>
							<th>玩家ID</th>
							<th>微信昵称</th>
							<th>真实姓名</th>
							<th>电话号码</th>
							<th>身份证号</th>
							<th>剩余{:L(GAME_RESOURCE)}</th>
							<th>剩余金币</th>
							<th>注册时间</th>
							<th>上次登录时间</th>
							<th colspan="2" id="set">管理操作</th>
						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</section>
			<div id="sub_tips">
				<ul>
					<li id="special"><span onclick="privClick()" data-toggle="modal" data-target="#kmyModal">{:L(GAME_SETTING_SPECIAL)}</span></li>
					<li id="wright"><span onclick='setClick(this)' data-toggle='modal' data-target="#myModal">{:L(GAME_SETTING_WEIGHT)}</span></li>
					<li><span onclick="resClick()" data-toggle="modal" data-target="#rmyModal">扣减资源</span></li>
					<li id="openAgent"><span id='setRole' onclick='roleClick(this)'>{:L(GAME_SETTING_AGENT)}</span></li>
					<li><span id='modRefer' onclick='referClick(this)' data-toggle="modal" data-target="#mrmyModal">{:L(GAME_MODREFER)}</span></li>
				</ul>
			</div>
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="exampleModalLabel">游戏ID权重设置</h4>
						</div>
						<div class="modal-body" style="padding-top: 0">
							<div class="row" >
								<div class="col-md-12">
									<h3>说明</h3>
									<p>该值是控制拿牌好坏的概率</p>
									<p>允许输入的值是0-100之间，值越大，概率越高；反之，越小</p>
									<div class="row">
										<div class="col-md-12">
											<div class="input-group">
												<span class="input-group-addon">游戏ID</span>
												<input type="text" class="form-control" name="uid" id="uid" disabled="true">
												<input type="hidden" id="hiddens"/>
											</div>
											<div class="input-group">
												<span class="input-group-addon">权重值</span>
												<input class="form-control" type="number" min="0" max="100" name="values" id="values" placeholder="请输入权重"/>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-primary" id="sbtn">设置</button>
						</div>
					</div>
				</div>
			</div>
			<div class="modal fade" id="kmyModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelk">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="exampleModalLabelk">专场图标显示设置</h4>
						</div>
						<div class="modal-body" style="padding-top: 0">
							<div class="row" >
								<div class="col-md-12">
									<h3>说明</h3>
									<p>该设置可控制客户端是否显示{:L(GAME_SESSION)}图标</p>
									<div class="row">
										<div class="col-md-12">
											<div class="input-group">
												<span class="input-group-addon">游戏ID&emsp;</span>
												<input type="text" class="form-control" name="uid" id="uidd" disabled="true">
											</div>
											<div class="input-group">
												<span class="input-group-addon">{:L(GAME_SESSION)}图标</span>
												<div class="form-control">
													<input type="radio" name="privilege" value="1" id="privilege1">显示
													<input type="radio" name="privilege" value="0" id="privilege0">不显示
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-primary" id="pbtn">确定</button>
						</div>
					</div>
				</div>
			</div>
			<div class="modal fade" id="rmyModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelr">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="exampleModalLabelr">扣减游戏ID的金币、房卡</h4>
						</div>
						<div class="modal-body" style="padding-top: 0">
							<div class="row" >
								<div class="col-md-12">
									<h3>说明</h3>
									<p>1、可扣减游戏玩家的房卡</p>
									<p>2、可扣减游戏玩家的金币</p>
									<div class="row">
										<div class="col-md-12">
											<div class="input-group">
												<span class="input-group-addon">游戏ID&emsp;</span>
												<input type="text" class="form-control" name="uid" id="uidr" disabled="true">
											</div>
											<div class="input-group">
												<span class="input-group-addon">{:L(GAME_RESOURCE)}数量</span>
												<input type="number" min="0" class="form-control" name="card" placeholder="请输入扣减{:L(GAME_RESOURCE)}" id="cards">
											</div>
											<div class="input-group">
												<span class="input-group-addon">金币数量</span>
												<input type="number" min="0" class="form-control" name="coin" placeholder="请输入扣减金币" id="coin">
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-primary" id="rbtn">确定</button>
						</div>
					</div>
				</div>
			</div>

			<div class="modal fade" id="mrmyModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelkm">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title" id="exampleModalLabelkm">修改玩家绑定者的账号</h4>
						</div>
						<div class="modal-body" style="padding-top: 0">
							<div class="row" >
								<div class="col-md-12">
									<h3>说明</h3>
									<p>若玩家的绑定者UID不小心输入错误，点此方可修改</p>
									<p>新绑定号栏不填写就默认解绑，若是填写即为修改</p>
									<div class="row">
										<div class="col-md-12">
											<div class="input-group">
												<span class="input-group-addon">游戏ID&emsp;</span>
												<input type="number" class="form-control" name="uid" id="mruid" disabled="true">
											</div>
											<div class="input-group">
												<span class="input-group-addon">原绑定号</span>
												<input type="text" class="form-control" name="omruid" id="omruid" disabled="true">
											</div>
											<div class="input-group">
												<span class="input-group-addon">新绑定号</span>
												<input type="text" class="form-control" name="nmruid" id="nmruid">
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-primary" id="mbtn">确定</button>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script type="text/javascript">
			$(function () {
				var wright = $.trim($("#wright").text());
				if(wright == '' || wright == 'GAME_SETTING_WEIGHT') {
				    $("#wright").hide();
				}
				var speciall = $.trim($("#special").text());
				if(speciall == '' || speciall == 'GAME_SETTING_SPECIAL') {
				    $("#special").hide();
				}
				var openAgent = $.trim($("#openAgent").text());
				if(openAgent == '' || openAgent == 'GAME_SETTING_AGENT') {
				    $("#openAgent").hide();
				}

				var modRefer = $.trim($("#modRefer").text());
				if(modRefer == '' || modRefer == 'GAME_MODREFER') {
				    $("#modRefer").closest("li").hide();
				}
            })
			$('#user_id').blur(function () {
	            var user_id = $.trim($('#user_id').val());
	            if (user_id != '') {
	                var url1 = "{:U('Admin/Login/checkedUidState')}";
	                $.ajax({
	                    type: "post",
	                    url: url1,
	                    data: {'user_id': user_id},
	                    dataType: "json",
	                    success: function (data) {
	                        if (data == 'unexist') {
	                        	alert("此UID无效！");
	                        	window.location.href="{:U('Admin/Main/playerManage')}";
	                            return false;
	                        } 
	                    }
	                });
	            }
	        });
			$("#cbtn").on("click",function(){

				 var user_id = $.trim($('#user_id').val());
				 if(user_id == '' || user_id == null) {
				     alert('游戏ID不能为空！');
				     $("#user_id").focus();
				 }
				 $.ajax({
				 	type:"post",
				 	url:"{:U('Admin/Main/userDetailInfo')}",
				 	dataType:"json",
				 	data:{'user_id':user_id},
				 	success:function(data) {
				 		var txt = '';
				 		if(data.hasOwnProperty('block') && data.block == 1) {
				 			txt = '恢复';
				 		}else{
				 			txt = '封号';
				 		}
				 		
				 		if(!data.status.coin) {
				 			data.status.coin = 0;
				 		}

				 		if(data.hasOwnProperty('privilege') && data.privilege == 1){
							$("#privilege1").attr('checked',true);
						}else{
                            $("#privilege0").attr('checked',true);
						}
				 		var str = '';
				 		var sTime = '';

                        if(data.marks.logoutTime == 0) {
                            sTime = 0;
                        }else{
                            sTime = getLocalTime(data.marks.logoutTime);
                        }

				 		if(data.hasOwnProperty('authenticationInfo')) {

                            str += "<tr><td class='user_id'>"+data._id+"<input type='hidden' class='invite' value='"+data.invite.inviter+"'/> </td><td>"+data.info.name+"</td><td>"+data.authenticationInfo.name+"</td><td>"+data.authenticationInfo.phone+"</td><td>"+data.authenticationInfo.id+"</td><td id='card_num'>"+data.status.card+"</td><td id='coin_num'>"+data.status.coin+"</td><td>"+getLocalTime(data.info.createTime)+"</td><td>"+sTime+"</td><td colspan='2'><button class='btn btn-primary' id='setHandel' onclick='setHandel()'>设置</button>&nbsp;<button class='btn btn-primary state' onclick='onClick(this)'>"+txt+"</button></td></tr>";
                        }else{
                            str += "<tr><td class='user_id'>"+data._id+"<input type='hidden' class='invite' value='"+data.invite.inviter+"'/></td><td>"+data.info.name+"</td><td>未认证</td><td>未认证</td><td>未认证</td><td id='card_num'>"+data.status.card+"</td><td id='coin_num'>"+data.status.coin+"</td><td>"+getLocalTime(data.info.createTime)+"</td><td>"+sTime+"</td><td colspan='2'><button class='btn btn-primary' id='setHandel' onclick='setHandel()'>设置</button>&nbsp;<button class='btn btn-primary state' onclick='onClick(this)'>"+txt+"</button></td></tr>";
                        }

				 		$("#dataList").html(str);
                        var datas = $.trim($("#setBtn").html());
                        if(datas == '' || datas == null) {
                            $("#setBtn").hide();
                        }
				 	}
				 });
			});
			
			function onClick(This){
				var user_id = $(This).closest("tr").find('td.user_id').text();
				var block = '';
				var valuee = $(This).html();

				if(confirm("确认要修改该游戏ID的状态吗？")) {
					if(valuee == '恢复') {
						block = 0;
					}else if(valuee == '封号') {
						block = 1;
					}
					$.ajax({
						type:"get",
						url:"{:U('Admin/Main/playerHandle')}?user_id=" + user_id,
						dataType:"json",
						data:{'block':block},
						success:function(data) {
							if(data == 'success') {
								alert("更改状态成功！");
								if(block == 1) {
								    $(".state").text('恢复');
								}else{
                                    $(".state").text('封号');
								}
							}else if(data == 'error') {
								alert("更改状态失败！");
								return false;
							}
						}
					});
				}
			}
			function  setClick(This) {
                var user_id = $("td.user_id").text();
				$("#uid").val(user_id);
				$.ajax({
					type:"post",
					url:"{:U('Admin/Main/uidWeightShow')}",
					dataType:"json",
					data:{'user_id':user_id},
					success:function (data) {
//						console.log(data);
						if(data != 'error' && data) {
						    if(data.hasOwnProperty('controlValue')) {
                                $("#values").val(data.controlValue);
							}else{
                                $("#values").val('');
							}
						}
                    }
				})
            }
			$("#values").keypress(function () {
                var conVal = $.trim($("#values").val());
                if(parseInt(conVal) < 0 || parseInt(conVal) >= 100) {
                    alert("权重值在0-100之间");
                    return false;
                }
            })

            $("#sbtn").on('click',function (data) {
				var conVal = $.trim($("#values").val());
				var user_id = $.trim($("#user_id").val());
				if(conVal == '') {
				    alert("值不能为空!");
				    return false;
				}
				if(parseInt(conVal) < 0 || parseInt(conVal) > 100) {
				    alert("权重值在0-100之间");
				    window.location.href="{:U('Admin/Main/playerManage')}";
				    return false;
				}
				$.ajax({
					type:"post",
					url:"{:U('Admin/Main/uidConvalSave')}",
					dataType:"json",
					data:{'user_id':user_id,'controlValue':conVal},
					success:function (data) {
						if(data == 'repeat') {
						    alert('不能重复相同的值');
						}else if(data == 'error') {
						    alert("设置失败！");
						}else if(data == 'success') {
						    alert("设置成功！");
						    $("#myModal").hide();
						    $(".modal-backdrop").hide();
						}
                    }
				})
            });
			function  roleClick() {
                var user_id = $.trim($("#user_id").val());
               if(confirm("你确定要将该玩家提升为代理吗？")) {
                   $.ajax({
					   type:"get",
					   url:"{:U('Admin/Main/uidRoleSet')}?user_id=" + user_id,
					   success:function (data) {
//					       console.log(data);
						   if(data == 'failure') {
						       alert("请求失败！");
                               window.location.href="{:U('Admin/Main/playerManage')}";
                           }else if(data == 'longtime') {
						       alert('请求超时！');
                               window.location.href="{:U('Admin/Main/playerManage')}";
                           }else if(data == 'exist') {
						       alert("该游戏UID已是代理了");
                           }else if(data == 'error') {
						       alert("开通失败！");
                               window.location.href="{:U('Admin/Main/playerManage')}";
                           }else if(data && data['state'] == 'success') {
							   alert('开通成功！该代理的登录密码是:'+data['password']);
						   }
                       }
				   })
			   }
            }
			function setHandel() {
				$("#sub_tips").toggle();
				$("#sub_tips").on("click",function () {
					$(this).hide();
                })
			}

			function privClick() {
                var user_id = $("td.user_id").text();
				$("#uidd").val(user_id);

            }
            $("#pbtn").on("click",function () {
                var privilege = $("input[name='privilege']:checked").val();
                var uid = $("#uidd").val();
                $.ajax({
                    type:'post',
                    url:"{:U('Admin/Main/uidPrivSet')}?",
                    dataType:"json",
                    data:{"uid":uid,"privilege":privilege},
                    success:function (data) {
                        if(data == 'success') {
                            alert("设置成功！");
                            $("#kmyModal").hide();
                            $(".modal-backdrop").hide();
						}else if(data == 'failure'){
                            alert("请求错误！");
                            window.location.href="{:U('Admin/Main/playerManage')}";
						}else if(data == 'error') {
						    alert("设置失败！");
                            window.location.href="{:U('Admin/Main/playerManage')}";
						}
                    }
                });
            })
            function resClick() {
                var user_id = $("td.user_id").text();
                $("#uidr").val(user_id);
            }
            $("#rbtn").on("click",function () {
                var card_num = $.trim($("#card_num").text());
                var coin_num = $.trim($("#coin_num").text());
				var card = $.trim($("#cards").val());
				var coin = $.trim($("#coin").val());
                var uid = $("#uidr").val();

				var res = /^([1-9]\d*|[0]{1,1})$/;
				if((card == '' && coin == '') && (card == 0 && coin == 0) ){
				    alert("扣减数量不能为空");
				    return false;
				}
				if(card*1>card_num*1 || coin*1>coin_num*1){
				    alert("扣减数量不能超过剩余数量！");
                    return false;
				}

				if(card != '' && parseInt(card) <1 ) {
				    alert("请注意输入的值！");
				    return false;
				}
                if(coin != '' && parseInt(coin) <1 ) {
                    alert("请注意输入的值！");
                    return false;
                }
				var datas = '';
				if(card == '' && coin != '' ) {
					datas = {'uid':uid,'coin':coin};
				}else if(coin == ''  && card != '') {
				    datas = {'uid':uid,'card':card}
				}else{
				    datas = {"uid":uid,"card":card,"coin":coin}
				}
				$.ajax({
					type:"post",
					url:"{:U('Admin/Main/uidResModify')}",
					dataType:"json",
					data:datas,
					success:function (data) {
						if(data == 'success') {
						    alert("扣除成功！");
						    $("#rmyModal").hide();
                            $(".modal-backdrop").hide();
                            $("#card_num").text(card_num*1 - card*1)
                            $("#coin_num").text(coin_num*1 - coin*1)
						}else if(data == 'error') {
						    alert("扣除失败！");
                            window.location.href="{:U('Admin/Main/playerManage')}";
						}
                    }
				})
            });
			function referClick(This) {
                var user_id = $("td.user_id").text();
                var orefer = $("td input.invite").val();
                if(orefer == 0) {
                    $("#omruid").val("无");
				}else{
                    $("#omruid").val(orefer);
				}
                $("#mruid").val(user_id);
			}

			$("#mbtn").on("click",function () {
                var user_id = $("td.user_id").text();
				var nrefer = $.trim($("#nmruid").val());
				var datas = '';
				if(nrefer == '' || nrefer == null) {
				    datas = {'refer':0,'user_id':user_id};
				}else{
                    datas = {'refer':nrefer,'user_id':user_id};
				}
				$.ajax({
					type:"post",
					url:"{:U('Admin/Main/setRefer')}",
                    dataType:'json',
					data:datas,
					success: function (data) {
						switch (data) {
							case 'error':
							    alert("请求失败！");
                                window.location.href="{:U('Admin/Main/playerManage')}";
							    break;
							case 'success':
							    alert("设置成功！");
							    window.location.href="{:U('Admin/Main/playerManage')}";
							    break;
							case 2301:
							    alert("不能绑定总管理员！");
                                window.location.href="{:U('Admin/Main/playerManage')}";
							    break;
							case 2302:
							    alert("不能绑定普通的玩家！");
                                window.location.href="{:U('Admin/Main/playerManage')}";
							    break;
							case 2303:
							    alert("不能绑定比代理级别低的代理");
                                window.location.href="{:U('Admin/Main/playerManage')}";
							    break;
						}
                    }
				})
            })
		</script>
	</body>
</html>
